package largeGroupPositions;

import java.util.ArrayList;
import java.util.List;

public class Solution {
    public List<List<Integer>> largeGroupPositions(String s) {
        // 双指针
        // 找相同元素
        int start = 0,end = 0,n = s.length();
        List<List<Integer>> ans = new ArrayList<>();
        while (end<n) {
            if(s.charAt(end) == s.charAt(start)) {
                end++;
            } else {
                if(end - start>=3) {
                    List<Integer> list = new ArrayList<>();
                    list.add(start);
                    list.add(end-1);
                    ans.add(list);
                }
                start = end;
            }
        }
        if(end - start>=3) {
            List<Integer> list = new ArrayList<>();
            list.add(start,end);
            ans.add(list);
        }
        return ans;
    }
}
